<extend name="public:template" />
<block name="title">邮件配置</block>
<block name="content">
    <div class="wrap-page">
        <div id="pageConfigSite" class="page-content">
            <include file="public:subtabs"/>
            <form class="form default-style" role="form" id="setting_site_form" action="{:u('backend/settings/index')}" method="post">
                <div id="boxConfigSite" class="box">
                    <div class="box-content">
                        <dl class="clearfix">
                            <dt><label>smtp服务器：</label></dt>
                            <dd>
                                <div class="item-field clearfix">
                                    <input  type="text" class="textfield" value="{$list.setting_email_host.data}" name="setting_email_host" placeholder="请输入smtp服务器" />
                                </div>
                            </dd>
                        </dl>
                        <dl class="clearfix">
                            <dt><label>发件地址：</label></dt>
                            <dd>
                                <div class="item-field clearfix">
                                    <input  type="text" class="textfield" value="{$list.setting_email_username.data}" name="setting_email_username"  placeholder="请输入发件人地址 如 admin@admin.com" />
                                </div>
                            </dd>
                        </dl>

                        <dl class="clearfix">
                            <dt><label>邮箱密码：</label></dt>
                            <dd>
                                <div class="item-field clearfix">
                                    <input  type="text" class="textfield" value="{$list.setting_email_password.data}" name="setting_email_password"  placeholder="请输入邮箱密码" />
                                </div>
                            </dd>
                        </dl>

                        <dl class="clearfix">
                            <dt><label>邮件编码：</label></dt>
                            <dd>
                                <div class="item-field clearfix">
                                    <input  type="text" class="textfield" value="{$list.setting_email_charset.data}" name="setting_email_charset"  placeholder="请输入邮件编码" />
                                </div>
                            </dd>
                        </dl>

                        <dl class="clearfix">
                            <dt><label>发件人姓名：</label></dt>
                            <dd>
                                <div class="item-field clearfix">
                                    <input  type="text" class="textfield" value="{$list.setting_email_from.data}" name="setting_email_from"  placeholder="请输入发件人姓名"/>
                                </div>
                            </dd>
                        </dl>

        </div>
    </div>
    <div class="page-buttons clearfix">
        <div class="fl-l">
            <button type="button" class="setting-btn button button-blue">保存</button>
        </div>
    </div>
    </form>

    <form class="form default-style">
        <div class="box-content">
        <dl class="clearfix">
            <dt><label>测试邮件：</label></dt>
            <dd>
                <div class="item-field clearfix">
                    <input  type="text" class="textfield" name="test_email" id="test_email" placeholder="请输入测试邮件"/>
                    <button class="button button-red" id="send_email" type="button">发送邮件</button>
                </div>
            </dd>
        </dl>
        </div>
    </form>
    </div>
    </div>
</block>

<block name="script">
    <script>
        $(document).ready(function(){

            $('.setting-btn').click(function(){
                var form_id = $(this).parents('form').prop('id');
                //数据验证
                $.ajax({
                    type: "POST",
                    url: $('#'+form_id).attr('action'),
                    data: $('#'+form_id).serialize(),
                    dataType: "json",
                    success:function(data){
                        if(data.status)
                        {
                            layer.msg(data.msg,{offset:[150],icon: 1,time:2000, shade: [0.1, '#ccc']});
                        } else {
                            layer.msg(data.msg,{offset:[150],icon: 2,time:2000, shade: [0.1, '#ccc']})
                        }

                    }
                });
                return false;
            });

            //发送测试邮件
            $('#send_email').click(function(){
                var url = "{:u('Backend/settings/email_test')}";
                $.post(url,{email: $.trim($('#test_email').val())},function(res){
                    layer.msg(res.msg,{time:2000,offset:[150]});
                },'json')
                return false;
            });
        });
    </script>
</block>